package com.jh.complicate.serializable;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * @author Administrator
 * @projectName newforward
 * @title XStreamSerializer.java
 * @package com.jh.complicate.serializable
 * @description XML序列化
 * @date 2019/6/5 09:49
 */
public class XStreamSerializer implements ISerializable{

    XStream xStream = new XStream(new DomDriver());

    @Override
    public <T> byte[] serialize(T obj) {
        return xStream.toXML(obj).getBytes();
    }

    @Override
    public <T> T deserialize(byte[] data, Class clazz) {
        return (T) xStream.fromXML(new String(data));
    }
}
